package main

import (
	"flag"
	"io"
	"log"
	"net"
	"net/http"

	"gitee.com/lwj8507/nggs/util"
)

var (
	flagAddr = flag.String("addr", ":8080", "listen address, default=:8080")
)

type handler struct {
}

func (s *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, r.URL.Path)
}

func main() {
	flag.Parse()

	ln, err := net.Listen("tcp", *flagAddr)
	if err != nil {
		log.Panicf("listen [%s] fail, %s", *flagAddr, err)
		return
	}

	svr := &http.Server{
		Handler: &handler{},
	}

	go svr.Serve(ln)

	util.WaitExitSignal()

	svr.Close()
}
